package com.jxtti.service;

import org.apache.log4j.Logger;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.jxtti.dao.SolicitPublicDao;
import com.jxtti.entity.SolicitPublic;


@Service("solicitPublicService")
@Transactional(rollbackFor = { RuntimeException.class, Exception.class })
public class SolicitPublicService {

	private final static Logger log= Logger.getLogger(SolicitPublicService.class);
	

	@Autowired
    private SolicitPublicDao<?> solicitPublicDao;		

	//后台分页
	public  PageInfo<SolicitPublic> list(Map<String, Object> data)
	{	
		// 第几页
		int pageNum = Integer.parseInt((data.get("page") == null || data.get("page").equals("0")) ? "1" : data.get("page").toString());
		// 每页显示条数 
		int pageSize = Integer.parseInt((data.get("rows") == null || data.get("rows").equals("0")) ? "10" : data.get("rows").toString());
			
		PageHelper.startPage(pageNum, pageSize);
		PageInfo<SolicitPublic> pages = new PageInfo<SolicitPublic>(solicitPublicDao.queryByList(data));		
		return pages;
	}
	
	
	// 前台分页
	public  PageInfo<SolicitPublic> listPage(Map<String, Object> data)
	{
		//第几页
		int pageNum = Integer.parseInt((data.get("currPageNum") == null || data.get("currPageNum").equals("0")) ? "1" : data.get("currPageNum").toString());
		// 每页显示条数 
		int pageSize = Integer.parseInt((data.get("pageRowSize") == null || data.get("pageRowSize").equals("0")) ? "10" : data.get("pageRowSize").toString());
		
		PageHelper.startPage(pageNum, pageSize);			
		PageInfo<SolicitPublic> pages = new PageInfo<SolicitPublic>(solicitPublicDao.queryByList(data));		
		return pages;
	}
	
	
	/**
	 * 查询所有数据。 
	 * @param data
	 * @return
	 */
	public List<SolicitPublic>  queryAll(Map<String, Object> data)
	{
		return  solicitPublicDao.queryByList(data);
	}
	
	
	/**
	 * 添加数据.
	 * 
	 * @param data
	 * @return
	 */
	public int add(SolicitPublic solicitPublic)
	{
		int insertCount = solicitPublicDao.add(solicitPublic);
		return insertCount;
	}
	

	/**
	 * 修改数据.
	 * 
	 * @param data
	 * @return
	 */
	public int update(SolicitPublic solicitPublic)
	{
		int updateCount = solicitPublicDao.update(solicitPublic);
		return updateCount;
	}
	

	/**
	 * 删除数据.
	 * 
	 * @param data
	 * @return
	 */
	public int delete(SolicitPublic solicitPublic)
	{
		int deleteCount = solicitPublicDao
				.delete(solicitPublic);
		
		return deleteCount;
	}
	
	
	public SolicitPublic queryById(SolicitPublic solicitPublic)
	{
		solicitPublic = solicitPublicDao.queryById(solicitPublic);
		return solicitPublic;
	}

}
